-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Update multiple_buttons.rst #12089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update multiple_buttons.rst #12089
Conversation
@@ -35,3 +35,9 @@ Or you can get the button's name by using the | |||
if ($form->getClickedButton() && 'saveAndAdd' === $form->getClickedButton()->getName()) { | |||
// ... | |||
} | |||
|
|||
If you have multiple buttons with the same name, each nested in multiple subforms, use direct reference instead the name to get the right button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would clarify here that this is related to a form name used multiple times. And we could also just add it inside the code block above. Maybe something like this:
Or you can get the button's name by using the
:method:`Symfony\\Component\\Form\\Form::getClickedButton` method of the form::
if ($form->getClickedButton() && 'saveAndAdd' === $form->getClickedButton()->getName()) {
// ...
}
// if you have multiple buttons with the same name, compare the object references instead
if ($form->getClickedButton() === $form->get('saveAndAdd')){
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but multiple buttons with the same name in the same form is not possible, so I wanted to clarify that it was in nested form situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe using @xabbuh's proposal + a small note about the "same name"?
@Romaxx would you like to finish this PR? |
b76bcff
to
194bca1
Compare
This PR was submitted for the 4.3 branch but it was merged into the 3.4 branch instead (closes #12089). Discussion ---------- Update multiple_buttons.rst Reference to symfony/symfony#32932 Commits ------- 194bca1 Update multiple_buttons.rst
@Romaxx thanks for contributing this improvement. I agreed both with you and @xabbuh so I reworded this as follows while merging:
|
Reference to symfony/symfony#32932